<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
//權限
admin_main::actionChk($_REQUEST['action']);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>處理中...</title>
<?
switch($_REQUEST['action'])
{
/*	************************************************************
	 ** 管理員管理
    ************************************************************ */  
	  case 'admin_add';
	 	if($db_admin->rowRepeat($menu['table'],$menu['masterField'],$_POST['account']))
		{
			echo g::msg('管理員ID已存在，請確認你輸入的管理員ID正確!');
			g::gowin('s_master.php?action=AdminAdd');
		}else
		{	
			$sql = array(
				$menu['masterField']	=> $_POST['account'],
				$menu['password']		=> admin_main::mixPass($_POST['password']),
				$menu['keyField']		=> implode(',',$_POST['chk']),
				$menu['noteField']		=> $_POST['note']
			);
			$db_admin->insert($menu['table'],$sql);
			g::gowin('s_master.php');
		}
	  break;	  
	  case 'admin_up_date';
	  	//更新權限
	  	$sql = array(
			$menu['keyField'] 	=>implode(',',$_POST['chk']),
			$menu['noteField']	=>$_POST['note']
		);
		if($_POST['password'])
		{
			$sql[$menu['password']] = admin_main::mixPass($_POST['password']);
		}
		$db_admin->update($menu['table'],$sql,' id = ? ',$_POST['id']);
		//檢查
	  	$rsCount=$db_admin->rsCount("SELECT `id` FROM `".$menu['table']."` WHERE `".$menu['keyField']."` LIKE '%admin_set%'");
		if(!$rsCount)
		{
			$sql = array(
				$menu['keyField'] 	=>implode(',',$_POST['chk']).",admin_set",
			);
			$db_admin->update($menu['table'],$sql,' id = ? ',$_POST['id']);
			echo g::msg("錯誤!設定『管理員管理』權限失敗!\n最少要有一個管理員ID，擁有『管理員管理』權限!");
		 }
		 $_SESSION[$menu['adminStr'].'admin_qx_'.$_POST['account_id']]	=	'';
		 echo g::gowin("s_master.php?action=modify&id=".$_POST['id']);
	 break;
	 case 'admin_Del';
	 	$rsArray=$db_admin->rsArray("select id,".$menu['masterField']." from ".$menu['table']."  where id= ? ",$_GET['id']);
		if($rsArray[$menu['masterField']] != $_SESSION[$menu['adminStr']])
		{
	 		$db_admin->delete($menu['table'],' id =? ',$_GET['id']);
		}else
		{
			echo g::msg("失敗!不能刪除自己!");
		}
		g::gowin('s_master.php');
	 break;
	 case 'modifyPassWorld';
	 	if(admin_main::login($_SESSION[$menu['adminStr']],$_POST['pwd'],$menu['table'],$menu['masterField'],$menu['password']))
		{
			$sql = array(
				$menu['password'] => admin_main::mixPass($_POST['newPwd'])
			);
			$db_admin->update($menu['table'],$sql," ".$menu['masterField']."= ? ",$_SESSION[$menu['adminStr']]);
			echo g::msg("成功!密碼更新成功!");
		}else
		{
			echo g::msg("錯誤!你輸入的舊密碼有誤!");
		}
		g::gowin("s_modifyPass.php");
	 break;
/*  ************************************************************
      ** bug 提交
    ************************************************************ */
	 case 'post_bug';
	 	$email='dreamxyp@gmail.com,dreamxyp@yahoo.com.cn';
	 	g::mail($email,$_POST['object'],$_POST['txt'],$_POST['from_']);
		echo g::msg("你BUG已成功提交！謝謝。");
	 	gowin('PostBug.php'); 
	 break; 
}
?>
</head>
</html>